package com.fat.thegioivere.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fat.thegioivere.R;
import com.fat.thegioivere.model.NavDrawerItem;

public class NavDrawerListAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<NavDrawerItem> mNavDrawerItems;
	LayoutInflater mInflater;

	public NavDrawerListAdapter(Context context,
			ArrayList<NavDrawerItem> navDrawerItems) {
		this.mContext = context;
		this.mNavDrawerItems = navDrawerItems;
		mInflater = (LayoutInflater) mContext
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return mNavDrawerItems.size();
	}

	@Override
	public Object getItem(int position) {
		return mNavDrawerItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.row_menu_item, null);

			holder = new ViewHolder();
			holder.icon = (ImageView) convertView
					.findViewById(R.id.imvIconMenu);
			holder.title = (TextView) convertView
					.findViewById(R.id.tvTitleMenuItem);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.icon.setImageResource(mNavDrawerItems.get(position).getIcon());
		holder.title.setText(mNavDrawerItems.get(position).getTitle());

		return convertView;
	}

	static class ViewHolder {
		public ImageView icon;
		public TextView title;
	}
}
